package com.zwj.service.impl;


import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.zwj.dto.Result;
import com.zwj.entity.CourseResourcesEntity;
import com.zwj.entity.SysMenuEntity;
import com.zwj.mapper.CourseResourcesMapper;
import com.zwj.service.CourseResourcesService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;

import org.springframework.stereotype.Service;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author zwj
 * @since 2021-11-02
 */
@Service
public class CourseResourcesServiceImpl extends ServiceImpl<CourseResourcesMapper, CourseResourcesEntity> implements CourseResourcesService {

    private final CourseResourcesMapper courseResourcesMapper;

    public CourseResourcesServiceImpl(CourseResourcesMapper courseResourcesMapper) {
        this.courseResourcesMapper= courseResourcesMapper;
    }

    @Override
    public Result addResources(CourseResourcesEntity courseResourcesEntity) {

        int row = courseResourcesMapper.insert(courseResourcesEntity);
        if (row == 0) {
            return Result.error().message("新增失败");
        }
        return Result.ok();
    }

    @Override
    public Result updateStatus(CourseResourcesEntity courseResourcesEntity) {

        UpdateWrapper<CourseResourcesEntity> updateWrapper = new UpdateWrapper<>();
        updateWrapper.lambda().eq(CourseResourcesEntity::getId, courseResourcesEntity.getId());
        int row = courseResourcesMapper.update(courseResourcesEntity,updateWrapper);
        if (row == 0) {
            return Result.error().message("修改失败");
        }
        return Result.ok();
    }


}
